# Contributor: Konstantin Kulikov <k.kulikov2@gmail.com>
# Maintainer: Konstantin Kulikov <k.kulikov2@gmail.com>
pkgname=grafana-image-renderer
pkgver=3.9.0
pkgrel=0
pkgdesc="Grafana Backend Plugin that handles rendering of panels & dashboards to PNGs using headless chrome"
url="https://github.com/grafana/grafana-image-renderer"
arch="x86_64" # Requires chromium, aarch64 and armv7 doesn't build because of grpc.
license="Apache-2.0"
makedepends="yarn"
depends="nodejs font-opensans chromium ca-certificates"
options="!check" # Has no test suite.
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/grafana/grafana-image-renderer/archive/v$pkgver.tar.gz
	$pkgname.initd $pkgname.confd $pkgname.json"

# secfixes:
#   3.6.1-r0:
#     - CVE-2022-31176

build() {
	export CHROME_BIN="/usr/bin/chromium-browser"
	export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

	yarn install --pure-lockfile --ignore-engines
	yarn --ignore-engines build
	find . -type f \( \
		-name '.*' -o \
		-name '*.cmd' -o \
		-name '*.bat' -o \
		-name '*.map' -o \
		-name '*.md' -o \
		\( -name '*.ts' -a ! -name '*.d.ts' \) -o \
		-name 'AUTHORS*' -o \
		-name 'LICENSE*' -o \
		-name 'license' -o \
		-name 'Makefile' -o \
		-name 'README*' -o \
		-name 'readme.markdown' \) -delete
}

package() {
	install -Dm755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.json" "$pkgdir/etc/$pkgname.json"
	install -dm755 "$pkgdir/usr/share/$pkgname"
	cp -r "$builddir/node_modules" "$builddir/build" "$builddir/proto" "$pkgdir/usr/share/$pkgname/"
}

sha512sums="
90150ea0c5c891d88a240b0c7028cabb1bb0a97ac1f4b1b070a74ebba38e0d3e59d239bbbfee7ca0925599ac7fdb7fb051fd0d4dc04f03d15b8741efefd89730  grafana-image-renderer-3.9.0.tar.gz
06faad0f5abecf434c014ca91dccf3f07f18d96a8f526c3c1d2384cba8db44db5fe2b2165d8fc12a8fe8d121135077b0c70158ee29ebb1bfba8dd2a3110b349c  grafana-image-renderer.initd
88a119ad18fbde490ab9213487ae16b8aeeb65437275a1112f7423fa581a7470e6fb68654c2fd439afa68c0333aeefd0711f3fffd53615fa51d0702c80ed1c1b  grafana-image-renderer.confd
8fc756536a429dc3343216e64fa33af8c601d83d03d81bd6096e46b33e5d1249f95be719ea489b13bd1af936771e8eeffd3ff7d8c5cdf622c3188b342c8fbdbd  grafana-image-renderer.json
"
